//
//  TBBLEDevice.m
//  TBSDK
//
//  Created by nexgo on 2017/10/27.
//  Copyright © 2017年 truth. All rights reserved.
//

#import "TBBLEDevice.h"

@implementation TBBLEDevice

- (instancetype)init:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(NSNumber *)RSSI{
    self = [super init];
    if (self) {
        [self refreshInfo:peripheral advertisementData:advertisementData RSSI:RSSI.intValue];
    }
    return self;
}

-(void)refreshInfo:(TBBLEDevice *)device{
    [self refreshInfo:device.peripheral advertisementData:device.advertisementData RSSI:device.rssi];
}

-(void)refreshInfo:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(int)RSSI{
    _peripheral = peripheral;
    _advertisementData = advertisementData;
    _currentRssi = RSSI;
    
    if(_rssi == 0){
        _rssi = _currentRssi;
    }else{
        _rssi = (_rssi + _currentRssi)/2;
    }
    
}

+(BOOL)isEque:(TBBLEDevice*)device1 device2:(TBBLEDevice*)device2{
    return [device1.peripheral.identifier.UUIDString isEqualToString:device2.peripheral.identifier.UUIDString];
}

@end
